home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 4 code / A⁄ROSE / ShowTasksƒ / ShowTasks.c next >
Encoding:
C/C++ Source or Header  |  1990-08-28  |  5.1 KB  |  242 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2. #
  3. # File  ShowTasks.c
  4. #
  5. # an A/ROSE programming exercise
  6. #
  7. #  MPW build commands:
  8. #
  9.         C  ShowTasks.c
  10.         Link -w -c 'MPS ' -t MPST ∂
  11.             ShowTasks.c.o ∂
  12.             "{CLibraries}"CSANELib.o ∂
  13.             "{CLibraries}"Math.o ∂
  14.             "{CLibraries}"StdClib.o ∂
  15.             "{CLibraries}"CInterface.o ∂
  16.             "{Libraries}"Stubs.o ∂
  17.             "{CLibraries}"CRuntime.o ∂
  18.             "{Libraries}"Interface.o ∂
  19.             "{Libraries}"ToolLibs.o ∂
  20.             "{AROSEPrep}"IPCGlue.o ∂
  21.             -o ShowTasks
  22. #
  23. ------------------------------------------------------------------------------*/
  24.  
  25. #include <Types.h>
  26. #include <Memory.h>
  27. #include <Packages.h>
  28. #include <Stdlib.h>
  29. #include <StdIO.h>
  30. #include <Slots.h>
  31. #include <String.h>
  32. #include <Strings.h>
  33.  
  34. //--- included from "os.h" :
  35.  
  36. typedef long    tid_type;
  37.  
  38. struct mMessage
  39. {
  40.     struct    mMessage    *mNext;
  41.     long                mId;
  42.     short                mCode;
  43.     short                mStatus;
  44.     unsigned    short    mPriority;
  45.     tid_type            mFrom;
  46.     tid_type            mTo;
  47.     unsigned    long    mSData [3];
  48.     unsigned    long    mOData [3];
  49.     long                mDataSize;        // Size of data buffer in bytes. set to negative 
  50.                                         // size of buffer if buffer is shared
  51.                                         // between tasks. eg. Buffer cannot be copied 
  52.     char                *mDataPtr;
  53. };
  54.  
  55. typedef struct mMessage mMessage;
  56.  
  57.  
  58. #define    OS_MATCH_ALL    0        // on receive match anything                
  59. #define    OS_NO_TIMEOUT    0        // receive waits forever for message        
  60.  
  61.  
  62. //--- included from "managers.h" :
  63.  
  64.  
  65. #define    NM_LOOKUP_NAME     104    // message code for "lookup name"    
  66.  
  67. // the following is a cosmetic variant of the original definition
  68.  
  69. typedef unsigned char Str33[34];
  70.  
  71. struct ra_lnm        // return area for lookup name    
  72. {
  73.     Str33     ra_on;        // object name                        
  74.     Str33     ra_tn;        // type name                        
  75. };
  76. typedef struct    ra_lnm ra_lnm;
  77.  
  78.  
  79. struct pb_lookup_name
  80. {
  81.     tid_type            lnm_tid;            // process id                        
  82.     unsigned    short    lnm_index;        // index        (INPUT/OUTPUT)        
  83.     unsigned    short    lnm_RAsize;        // size of return area                
  84.     ra_lnm            lnm_ra [1];        // return area        (OUTPUT)        
  85. };
  86. typedef struct pb_lookup_name  pb_lookup_name;
  87.  
  88.  
  89. #define    ICC_GETCARDS    150
  90. // Get list of active cards and their name manager addresses.         
  91. // mDataPtr points to an array of 16 longwords (indexed by slots) 
  92. // On return, and entry < 0 means card not present,                    
  93.                             // = 0 means card present - no name manager,    
  94.                             // > 0 means TID of name manager on card        
  95.                             //     may be used in mTo field of a message    
  96.  
  97.  
  98. // prototypes:
  99.  
  100. void main();
  101. Boolean     AskICCM();
  102. void namelookup(tid_type ntid, tid_type tid);
  103. void NumToHex( long n, short d, char *s);
  104.  
  105. extern void            FreeMsg();
  106. extern mMessage    *GetMsg(void);
  107. extern mMessage    *Receive();
  108. extern void            Send(mMessage *);
  109.  
  110. extern tid_type    GetTID(void);
  111. extern tid_type    GetICCTID(void);
  112. extern tid_type    Lookup_Task(char *, char *, tid_type, unsigned short *);
  113.  
  114. extern tid_type        OpenQueue();
  115. extern void            CloseQueue();
  116.  
  117. static tid_type  cards[16];
  118.  
  119. void main()
  120. {
  121.     short                slot;
  122.     tid_type            tid;
  123.     unsigned short    index;
  124.     
  125.     if (! OpenQueue(0)) {
  126.             printf("### (OpenQueue fails) \n");
  127.             return;
  128.     }
  129.  
  130.     if (! AskICCM()) {
  131.             printf("### (AskICCM fails) \n");
  132.             return;
  133.     }
  134.     
  135.     for (slot=0; slot<15; slot++) {
  136.         if (cards[slot] > 0)
  137.         {
  138.             printf("\nslot = $%X :\n",slot);
  139.             index = 0;
  140.             while ((tid = Lookup_Task ("=", "=", cards[slot], &index)))
  141.                 namelookup(cards[slot], tid);
  142.         }
  143.     }
  144.  
  145.     CloseQueue ();
  146.  
  147. } // main()
  148.  
  149.  
  150.  
  151. Boolean     AskICCM()
  152. {
  153.     Boolean result;
  154.     mMessage    *m;
  155.     
  156.     
  157.     if (GetICCTID() != 0)
  158.     {
  159.         if ((m = GetMsg ()) == 0) {
  160.                 printf("### (GetMsg fails) \n");
  161.                 return(false);
  162.         }
  163.     
  164.         m -> mTo     = GetICCTID ();
  165.         m -> mCode     = ICC_GETCARDS;
  166.         m -> mDataPtr     = (char *) cards;
  167.         m -> mDataSize = sizeof (tid_type) * 16;
  168.         Send (m);
  169.         m = Receive (OS_MATCH_ALL, OS_MATCH_ALL, ICC_GETCARDS+1, OS_NO_TIMEOUT, 0);
  170.         result = (m -> mStatus == 0);  // slotInfo is in cards[0..15] !
  171.         FreeMsg(m);
  172.         return(result);
  173.     }
  174.     else
  175.         return(false);
  176.         
  177. } //     AskICCM()
  178.  
  179.  
  180. #define bufferSize 512
  181.  
  182. void namelookup(tid_type ntid, tid_type tid)
  183. {
  184.     pb_lookup_name    *lnam_ptr;
  185.     char    buffer[bufferSize];
  186.     char     sn[33];
  187.     mMessage *m;
  188.     
  189.     if ((m = GetMsg ()) == 0) {
  190.             printf("### (GetMsg fails) \n");
  191.             return;
  192.     }
  193.     m -> mTo   = ntid;
  194.     m -> mCode = NM_LOOKUP_NAME;
  195.     m -> mDataPtr  = buffer;
  196.     m -> mDataSize = bufferSize;
  197.     
  198.     lnam_ptr = (pb_lookup_name *) &buffer;
  199.     lnam_ptr -> lnm_index = 0;
  200.     lnam_ptr -> lnm_tid   = tid;
  201.     lnam_ptr -> lnm_RAsize = bufferSize - (sizeof(pb_lookup_name) - sizeof(ra_lnm));
  202.  
  203.     Send (m);
  204.     m = Receive (OS_MATCH_ALL, OS_MATCH_ALL, NM_LOOKUP_NAME+1, OS_NO_TIMEOUT, 0);
  205.     
  206.     if (m -> mStatus == 0) {
  207.         NumToHex(tid, 8, sn);
  208.         printf("$%s: name \"",sn+1);
  209.         strcpy(sn, ((pb_lookup_name *)(m -> mDataPtr)) -> lnm_ra[0].ra_on);
  210.         p2cstr(sn);
  211.         printf("%s", sn);
  212.         printf("\", type \"");
  213.         strcpy(sn, ((pb_lookup_name *)(m -> mDataPtr)) -> lnm_ra[0].ra_tn);
  214.         p2cstr(sn);
  215.         printf("%s", sn);
  216.         printf("\"\n");
  217.     }
  218.     else 
  219.         printf("Receive in NameLookup failed\n\n");
  220.  
  221.     FreeMsg(m);
  222.     
  223. } // namelookup()
  224.  
  225.  
  226.  
  227. void NumToHex( long n, short d, char *s)   // I hate this @#%@ ! 
  228. // s must point to at least d+1 free bytes - returns 0-terminated Pascal String of length d 
  229. // requires d > 0 
  230. {
  231.     short c;
  232.     
  233.     s[0] = d;
  234.     s[d+1] = 0x0;
  235.     do {
  236.         c =  (n & 0x0F) + 48;
  237.         if (c>57)
  238.             c = c+7;
  239.         s[d--] = (char) c;
  240.         n = n>>4;
  241.     } while (d > 0);
  242. } // NumToHex()